package com.ssm.springboot.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.springboot.dao.QfClassifyDao;
import com.ssm.springboot.pojo.DataInfo;
import com.ssm.springboot.pojo.QfClassify;
import com.ssm.springboot.pojo.QfTeach;
import com.ssm.springboot.service.QfClassifyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * (QfClassify)表服务实现类
 *
 * @author makejava
 * @since 2021-12-23 19:39:22
 */
@Service
public class QfClassifyServiceImpl implements QfClassifyService {
    @Resource
    private QfClassifyDao qfClassifyDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public DataInfo queryById(Integer id) {
        QfClassify qfClassify = qfClassifyDao.queryById(id);
        return new DataInfo(0,null,null,qfClassify);
    }

    /**
     * 查询多条数据
     *
     * @return 对象列表
     * @param page
     * @param limit
     */
    @Override
    public DataInfo queryAllByLimit(int page, int limit) {
        PageHelper.startPage(page,limit);
        List<QfClassify> qfClassifies = qfClassifyDao.queryAllByLimit();
        PageInfo<QfClassify> qfClassifyPageInfo = PageInfo.of(qfClassifies);
        return new DataInfo(0,"查询成功",qfClassifyPageInfo.getTotal(),qfClassifyPageInfo.getList());

    }

    /**
     * 新增数据
     *
     * @param qfClassify 实例对象
     * @return 实例对象
     */
    @Override
    public DataInfo insert(QfClassify qfClassify) {
        qfClassify.setCreatetime(new Timestamp(System.currentTimeMillis()));
        qfClassifyDao.insert(qfClassify);
        return new DataInfo(0,null,null,null);
    }

    /**
     * 修改数据
     *
     * @param qfClassify 实例对象
     * @return 实例对象
     */
    @Override
    public DataInfo update(QfClassify qfClassify) {
        qfClassify.setUpdatetime(new Date());

        qfClassifyDao.update(qfClassify);
        return  new DataInfo(0,null,null,null);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public DataInfo deleteById(Integer id) {
        qfClassifyDao.deleteById(id);
        return new DataInfo(0,null,null,null);
    }
}